import java.util.Arrays;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2022-09-02
 * Time: 9:15
 */
public class TestTime {
    //有序数组
    public static void orderArray(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
        }
    }
    //无序数组
    public static void rondomArray(int[] array){
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10_0000);
        }
    }
    public static void insertSortTime(int[] array){
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.insertSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("插入排序消耗的时间:"+(endTime-startTime));
    }
    public static void shellSortTime(int[] array){
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.shellSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序消耗的时间:"+(endTime-startTime));
    }
    public static void selectSortTime(int[] array){
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序消耗的时间:"+(endTime-startTime));
    }
    public static void selectSort1Time(int[] array){
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort1(array);
        long endTime = System.currentTimeMillis();
        System.out.println("max和min选择排序消耗的时间:"+(endTime-startTime));
    }
    public static void heapSortTime(int[] array){
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.heapSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序消耗的时间:"+(endTime-startTime));
    }
    public static void bubbleSortTime(int[] array){
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.bubbleSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("冒泡排序消耗的时间:"+(endTime-startTime));
    }
    public static void quickSortTime(int[] array){
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序消耗的时间:"+(endTime-startTime));
    }
    public static void quickStack(int[] array){
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("非递归快速排序消耗的时间:"+(endTime-startTime));
    }
    public static void main(String[] args) {
        //array1有序数组
        int[] array1 = new int[10_000];
        //array2无序数组
        int[] array2 = new int[1000_0000];
        orderArray(array1);
        rondomArray(array2);
//        insertSortTime(array1);
//        shellSortTime(array1);
//        selectSortTime(array1);
//        selectSort1Time(array1);
//        heapSortTime(array1);
         bubbleSortTime(array1);
          quickSortTime(array1);

//        System.out.println("=============");
//        insertSortTime(array2);
        shellSortTime(array2);
//        selectSortTime(array2);
//        selectSort1Time(array2);
       heapSortTime(array2);
 //       bubbleSortTime(array2);
        quickSortTime(array2);
        quickStack(array2);

    }
}
